package hadoop.ch03.v17034460231;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.net.URI;

public class DownloadHDFSFile {
    public static void main (String[] args) throws  Exception {
        Configuration conf = new Configuration();
        URI uri = new URI("hdfs://192.168.30.131:8020");// 配置NameNode地址
        FileSystem fs = FileSystem.get(uri, conf, "hadoop"); // 指定用户名,获取FileSystem对象
        Path dfs = new Path("/17034460231/test5.txt");//定义文件路径
        FSDataOutputStream os = fs.create(dfs, true);
        os.writeBytes("Hello World");//往文件写入信息
        //HDFS life
        Path src = new Path("/17034460231/test5.txt");
        //local file
        Path dst = new Path("/d:\\test5.txt");
        //window下
        fs.copyToLocalFile(false,src,dst,true);
        fs.close();//关闭FileSystem

        System.out.println("Download Successfully!");
    }
}
